package edu.gatech.cc.hwa.server.features;

import java.util.Calendar;

import edu.gatech.cc.hwa.server.Profile;

public class TimeOfDayFeature extends Feature {

	public static final int ANY = -1;
	public static final int MORNING = 0;
	public static final int AFTERNOON = 1;
	public static final int EVENING = 2;
	
	private long time;
	
	public TimeOfDayFeature() {
		super(System.currentTimeMillis()+"");
		time = Long.parseLong(getRawData());
	}

	@Override
	public boolean matchesProfile(Profile profile) {
		int profileTime = profile.getTimeOfDay();
		return (profileTime == ANY) || profileTime == mapToId();
	}
	
	public int mapToId() {
		return mapToId(time);
	}

	public static int mapToId(long time) {
		Calendar cal = Calendar.getInstance();
		cal.setTimeInMillis(time);
		int hourOfDay = cal.get(Calendar.HOUR_OF_DAY);
		if (hourOfDay < 12) 
			return MORNING;
		else if (hourOfDay < 6) 
			return AFTERNOON;
		else 
			return EVENING;
	}
}
